<?php
namespace BP\Sys;

use BP\En\EntityMyPK;

require_once("BP/En/Map.php");
class MapExt extends EntityMyPK {
	public function PopValToJson () 
	{
		return $BP->Tools->Json->ToJsonEntityModel($this->PopValToHashtable());
	}
	public function PopValToHashtable () 
	{
		$ht = new Hashtable();
		switch ($this->getPopValWorkModel()) {
			case $SelfUrl:
				$ht->put("URL", $this->getPopValUrl());
				break;
			case $TableOnly:
				$ht->put("EntitySQL", $this->getPopValEntitySQL());
				break;
			case $TablePage:
				$ht->put("PopValTablePageSQL", $this->getPopValTablePageSQL());
				$ht->put("PopValTablePageSQLCount", $this->getPopValTablePageSQLCount());
				break;
			case $Group:
				$ht->put("GroupSQL", $this->getTag1());
				$ht->put("EntitySQL", $this->getPopValEntitySQL());
				break;
			case $Tree:
				$ht->put("TreeSQL", $this->getPopValTreeSQL());
				$ht->put("TreeParentNo", $this->getPopValTreeParentNo());
				break;
			case $TreeDouble:
				$ht->put("DoubleTreeSQL", $this->getPopValTreeSQL());
				$ht->put("DoubleTreeParentNo", $this->getPopValTreeParentNo());
				$ht->put("DoubleTreeEntitySQL", $this->getPopValDoubleTreeEntitySQL());
				break;
			default:
				break;
		}
		$ht->put(MapExtAttr::$W, $this->getW());
		$ht->put(MapExtAttr::$H, $this->getH());
		$ht->put("PopValWorkModel", $this->getPopValWorkModel());
		$ht->put("PopValSelectModel", $this->getPopValSelectModel());
		$ht->put("PopValFormat", $this->getPopValFormat());
		$ht->put("PopValTitle", $this->getPopValTitle());
		$ht->put("PopValColNames", $this->getPopValColNames());
		$ht->put("PopValSearchTip", $this->getPopValSearchTip());
		$ht->put("PopValSearchCond", $this->getPopValSearchCond());
		return $ht;
	}
	public function getPopValUrl () 
	{
		return $this->getDoc();
	}
	public function setPopValUrl ($value) // [String value]
	{
		$this->setDoc($value);
	}
	public function getPopValEntitySQL () 
	{
		return $this->getTag2();
	}
	public function setPopValEntitySQL ($value) // [String value]
	{
		$this->setTag2($value);
	}
	public function getPopValGroupSQL () 
	{
		return $this->getTag1();
	}
	public function setPopValGroupSQL ($value) // [String value]
	{
		$this->setTag1($value);
	}
	public function getPopValTablePageSQL () 
	{
		return $this->getTag();
	}
	public function setPopValTablePageSQL ($value) // [String value]
	{
		$this->setTag($value);
	}
	public function getPopValTablePageSQLCount () 
	{
		return $this->getTag1();
	}
	public function setPopValTablePageSQLCount ($value) // [String value]
	{
		$this->setTag1($value);
	}
	public function getPopValTitle () 
	{
		return $this->GetParaString("PopValTitle");
	}
	public function setPopValTitle ($value) // [String value]
	{
		$this->SetPara("PopValTitle", $value);
	}
	public function getPopValTreeSQL () 
	{
		return $this->getPopValEntitySQL();
	}
	public function setPopValTreeSQL ($value) // [String value]
	{
		$this->setPopValEntitySQL($value);
	}
	public function getPopValTreeParentNo () 
	{
		return $this->GetParaString("PopValTreeParentNo");
	}
	public function setPopValTreeParentNo ($value) // [String value]
	{
		$this->SetPara("PopValTreeParentNo", $value);
	}
	public function getPopValFormat () 
	{
		return PopValFormat->forValue($this->GetParaInt("PopValFormat"));
	}
	public function setPopValFormat ($value) // [PopValFormat value]
	{
		$this->SetPara("PopValFormat", $value->getValue());
	}
	public function getPopValDoubleTreeEntitySQL () 
	{
		return $this->getTag1();
	}
	public function setPopValDoubleTreeEntitySQL ($value) // [String value]
	{
		$this->setTag1($value);
	}
	public function getPopValSelectModel () 
	{
		return PopValSelectModel->forValue($this->GetParaInt("PopValSelectModel"));
	}
	public function setPopValSelectModel ($value) // [PopValSelectModel value]
	{
		$this->SetPara("PopValSelectModel", $value->getValue());
	}
	public function getPopValWorkModel () 
	{
		return PopValWorkModel->forValue($this->GetParaInt("PopValWorkModel"));
	}
	public function setPopValWorkModel ($value) // [PopValWorkModel value]
	{
		$this->SetPara("PopValWorkModel", $value->getValue());
	}
	public function getPopValColNames () 
	{
		return $this->getTag3();
	}
	public function setPopValColNames ($value) // [String value]
	{
		$this->setTag3($value);
	}
	public function getPopValSearchCond () 
	{
		return $this->getTag4();
	}
	public function setPopValSearchCond ($value) // [String value]
	{
		$this->setTag4($value);
	}
	public function getPopValSearchTip () 
	{
		return $this->GetParaString("PopValSearchTip", "请输入关键字");
	}
	public function setPopValSearchTip ($value) // [String value]
	{
		$this->SetPara("PopValSearchTip", $value);
	}
	public function getFK_DBSrc () 
	{
		return $this->GetValStrByKey(MapExtAttr::$FK_DBSrc);
	}
	public function setFK_DBSrc ($value) // [String value]
	{
		$this->SetValByKey(MapExtAttr::$FK_DBSrc, $value);
	}
	public function getExtDesc () 
	{
		$dec = "";
		switch ($this->getExtType()) {
			case MapExtXmlList::$ActiveDDL:
				$dec += ("字段" . $this->getAttrOfOper());
				break;
			case MapExtXmlList::$TBFullCtrl:
				$dec += $this->getAttrOfOper();
				break;
			case MapExtXmlList::$DDLFullCtrl:
				$dec += ("" . $this->getAttrOfOper());
				break;
			case MapExtXmlList::$InputCheck:
				$dec += ((("字段�?" . $this->getAttrOfOper()) . " �?查内容：") . $this->getTag1());
				break;
			case MapExtXmlList::$PopVal:
				$dec += ((("字段�?" . $this->getAttrOfOper()) . " Url�?") . $this->getTag());
				break;
			default:
				break;
		}
		return $dec;
	}
	public function getIsAutoSize () 
	{
		return $this->GetValBooleanByKey(MapExtAttr::$IsAutoSize);
	}
	public function setIsAutoSize ($value) // [boolean value]
	{
		$this->SetValByKey(MapExtAttr::$IsAutoSize, $value);
	}
	public function getDBType () 
	{
		return $this->GetValStrByKey(MapExtAttr::$DBType);
	}
	public function setDBType ($value) // [String value]
	{
		$this->SetValByKey(MapExtAttr::$DBType, $value);
	}
	public function getAtPara () 
	{
		return $this->GetValStrByKey(MapExtAttr::$AtPara);
	}
	public function setAtPara ($value) // [String value]
	{
		$this->SetValByKey(MapExtAttr::$AtPara, $value);
	}
	public function getExtType () 
	{
		return $this->GetValStrByKey(MapExtAttr::$ExtType);
	}
	public function setExtType ($value) // [String value]
	{
		$this->SetValByKey(MapExtAttr::$ExtType, $value);
	}
	public function getDoWay () 
	{
		return $this->GetValIntByKey(MapExtAttr::$DoWay);
	}
	public function setDoWay ($value) // [int value]
	{
		$this->SetValByKey(MapExtAttr::$DoWay, $value);
	}
	public function getAttrOfOper () 
	{
		return $this->GetValStrByKey(MapExtAttr::$AttrOfOper);
	}
	public function setAttrOfOper ($value) // [String value]
	{
		$this->SetValByKey(MapExtAttr::$AttrOfOper, $value);
	}
	public function getAttrsOfActive () 
	{
		return $this->GetValStrByKey(MapExtAttr::$AttrsOfActive);
	}
	public function setAttrsOfActive ($value) // [String value]
	{
		$this->SetValByKey(MapExtAttr::$AttrsOfActive, $value);
	}
	public function getFK_MapData () 
	{
		return $this->GetValStrByKey(MapExtAttr::$FK_MapData);
	}
	public function setFK_MapData ($value) // [String value]
	{
		$this->SetValByKey(MapExtAttr::$FK_MapData, $value);
	}
	public function getDoc () 
	{
		$str = $this->GetValStrByKey("Doc")->replace("~", "'");
		$str = $str->replace("~", "'");
		return $str;
	}
	public function setDoc ($value) // [String value]
	{
		$str = $value->replace("'", "~");
		$this->SetValByKey("Doc", $str);
	}
	public function AutoFullDLL_SQL_ForDtl ($htMainEn, $htDtlEn) // [Hashtable htMainEn, Hashtable htDtlEn]
	{
		$fullSQL = $this->getDoc()->replace("@WebUser.getNo()", $WebUser->getNo());
		$fullSQL = $fullSQL->replace("@WebUser.getName()", $WebUser->getName());
		$fullSQL = $fullSQL->replace("@WebUser.getFK_Dept()", $WebUser->getFK_Dept());
		$fullSQL = $fullSQL->replace("@WebUser.getFK_DeptName", $WebUser->getFK_DeptName());
		if ($fullSQL->contains("@"))
		{
			foreach ($htDtlEn->keySet() as $key1) 			{
				$key = $key1;
				if (($fullSQL->contains("@") ==  FALSE ))
				{
					break;
				}
				if (($fullSQL->contains((("@" . $key) . ";")) ==  TRUE ))
				{
					$fullSQL = $fullSQL->replace((("@" . $key) . ";"), ( ($htDtlEn->get($key) instanceof String) ? $htDtlEn->get($key) : NULL ));
				}
				if (($fullSQL->contains(("@" . $key)) ==  TRUE ))
				{
					$fullSQL = $fullSQL->replace(("@" . $key), ( ($htDtlEn->get($key) instanceof String) ? $htDtlEn->get($key) : NULL ));
				}
			}
		}
		if ($fullSQL->contains("@"))
		{
			foreach ($htMainEn->keySet() as $key1) 			{
				$key = $key1;
				if (($fullSQL->contains("@") ==  FALSE ))
				{
					break;
				}
				if (($fullSQL->contains((("@" . $key) . ";")) ==  TRUE ))
				{
					$fullSQL = $fullSQL->replace((("@" . $key) . ";"), ( ($htMainEn->get($key) instanceof String) ? $htMainEn->get($key) : NULL ));
				}
				if (($fullSQL->contains(("@" . $key)) ==  TRUE ))
				{
					$fullSQL = $fullSQL->replace(("@" . $key), ( ($htMainEn->get($key) instanceof String) ? $htMainEn->get($key) : NULL ));
				}
			}
		}
		return $fullSQL;
	}
	public function getTagOfSQL_autoFullTB () 
	{
		if ($DataType->IsNullOrEmpty($this->getTag()))
		{
			return $this->getDocOfSQLDeal();
		}
		$sql = $this->getTag();
		$sql = $sql->replace("@WebUser.getNo()", $WebUser->getNo());
		$sql = $sql->replace("@WebUser.getName()", $WebUser->getName());
		$sql = $sql->replace("@WebUser.getFK_DeptNameOfFull", $WebUser->getFK_DeptNameOfFull());
		$sql = $sql->replace("@WebUser.getFK_DeptName", $WebUser->getFK_DeptName());
		$sql = $sql->replace("@WebUser.getFK_Dept()", $WebUser->getFK_Dept());
		return $sql;
	}
	public function getDocOfSQLDeal () 
	{
		$sql = $this->getDoc();
		$sql = $sql->replace("@WebUser.getNo()", $WebUser->getNo());
		$sql = $sql->replace("@WebUser.getName()", $WebUser->getName());
		$sql = $sql->replace("@WebUser.getFK_DeptNameOfFull", $WebUser->getFK_DeptNameOfFull());
		$sql = $sql->replace("@WebUser.getFK_DeptName", $WebUser->getFK_DeptName());
		$sql = $sql->replace("@WebUser.getFK_Dept()", $WebUser->getFK_Dept());
		return $sql;
	}
	public function getTag () 
	{
		$s = $this->GetValStrByKey("Tag")->replace("~", "'");
		$s = $s->replace("\\\\", "\\");
		$s = $s->replace("\\\\", "\\");
		$s = $s->replace("CCFlow\\Data\\", "CCFlow\\WF\\Data\\");
		return $s;
	}
	public function setTag ($value) // [String value]
	{
		$this->SetValByKey("Tag", $value);
	}
	public function getTag1 () 
	{
		return $this->GetValStrByKey("Tag1")->replace("~", "'");
	}
	public function setTag1 ($value) // [String value]
	{
		$this->SetValByKey("Tag1", $value);
	}
	public function getTag2 () 
	{
		return $this->GetValStrByKey("Tag2")->replace("~", "'");
	}
	public function setTag2 ($value) // [String value]
	{
		$this->SetValByKey("Tag2", $value);
	}
	public function getTag3 () 
	{
		return $this->GetValStrByKey("Tag3")->replace("~", "'");
	}
	public function setTag3 ($value) // [String value]
	{
		$this->SetValByKey("Tag3", $value);
	}
	public function getTag4 () 
	{
		return $this->GetValStrByKey("Tag4")->replace("~", "'");
	}
	public function setTag4 ($value) // [String value]
	{
		$this->SetValByKey("Tag4", $value);
	}
	public function getH () 
	{
		return $this->GetValIntByKey(MapExtAttr::$H);
	}
	public function setH ($value) // [int value]
	{
		$this->SetValByKey(MapExtAttr::$H, $value);
	}
	public function getW () 
	{
		return $this->GetValIntByKey(MapExtAttr::$W);
	}
	public function setW ($value) // [int value]
	{
		$this->SetValByKey(MapExtAttr::$W, $value);
	}
	public static function constructor__ () 
	{
		$me = new self();
		return $me;
	}
	public static function constructor__String ($mypk) // [String mypk]
	{
		$me = new self();
		$me->setMyPK($mypk);
		$me->Retrieve();
		return $me;
	}
	public function getEnMap () 
	{
		if (($this->get_enMap() != NULL))
		{
			return $this->get_enMap();
		}
		$map = new Map("Sys_MapExt", "业务逻辑");
		$map->Java_SetDepositaryOfEntity($Depositary->None);
		$map->Java_SetDepositaryOfMap($Depositary->Application);
		$map->Java_SetEnType($EnType->Sys);
		$map->IndexField = MapDtlAttr::$FK_MapData;
		$map->AddMyPK();
		$map->AddTBString(MapExtAttr::$FK_MapData, NULL, "主表",  TRUE ,  FALSE , 0, 100, 20);
		$map->AddTBString(MapExtAttr::$ExtType, NULL, "类型",  TRUE ,  FALSE , 0, 30, 20);
		$map->AddTBInt(MapExtAttr::$DoWay, 0, "执行方式",  TRUE ,  FALSE );
		$map->AddTBString(MapExtAttr::$AttrOfOper, NULL, "操作的Attr",  TRUE ,  FALSE , 0, 30, 20);
		$map->AddTBString(MapExtAttr::$AttrsOfActive, NULL, "�?活的字段",  TRUE ,  FALSE , 0, 900, 20);
		$map->AddTBStringDoc();
		$map->AddTBString(MapExtAttr::$Tag, NULL, "Tag",  TRUE ,  FALSE , 0, 2000, 20);
		$map->AddTBString(MapExtAttr::$Tag1, NULL, "Tag1",  TRUE ,  FALSE , 0, 2000, 20);
		$map->AddTBString(MapExtAttr::$Tag2, NULL, "Tag2",  TRUE ,  FALSE , 0, 2000, 20);
		$map->AddTBString(MapExtAttr::$Tag3, NULL, "Tag3",  TRUE ,  FALSE , 0, 2000, 20);
		$map->AddTBString(MapExtAttr::$Tag4, NULL, "Tag4",  TRUE ,  FALSE , 0, 2000, 20);
		$map->AddTBString(MapExtAttr::$Tag5, NULL, "Tag5",  TRUE ,  FALSE , 0, 2000, 20);
		$map->AddTBInt(MapExtAttr::$H, 500, "高度",  FALSE ,  FALSE );
		$map->AddTBInt(MapExtAttr::$W, 400, "宽度",  FALSE ,  FALSE );
		$map->AddTBInt(MapExtAttr::$DBType, 0, "数据类型",  TRUE ,  FALSE );
		$map->AddTBString(MapExtAttr::$FK_DBSrc, NULL, "数据�?",  TRUE ,  FALSE , 0, 100, 20);
		$map->AddTBInt(MapExtAttr::$PRI, 0, "PRI/顺序�?",  FALSE ,  FALSE );
		$map->AddTBString(MapExtAttr::$AtPara, NULL, "参数",  TRUE ,  FALSE , 0, 3999, 20);
		$this->set_enMap($map);
		return $this->get_enMap();
	}
	public function InitPK () 
	{
		switch ($this->getExtType()) {
			case MapExtXmlList::$FullData:
				break;
			case MapExtXmlList::$ActiveDDL:
				$this->setMyPK(((((MapExtXmlList::$ActiveDDL . "_") . $this->getFK_MapData()) . "_") . $this->getAttrOfOper()));
				break;
			case MapExtXmlList::$DDLFullCtrl:
				$this->setMyPK(((((MapExtXmlList::$DDLFullCtrl . "_") . $this->getFK_MapData()) . "_") . $this->getAttrOfOper()));
				break;
			case MapExtXmlList::$PopVal:
				$this->setMyPK(((((MapExtXmlList::$PopVal . "_") . $this->getFK_MapData()) . "_") . $this->getAttrOfOper()));
				break;
			case MapExtXmlList::$TBFullCtrl:
				$this->setMyPK(((((MapExtXmlList::$TBFullCtrl . "_") . $this->getFK_MapData()) . "_") . $this->getAttrOfOper()));
				break;
			case MapExtXmlList::$PopFullCtrl:
				$this->setMyPK(((((MapExtXmlList::$PopFullCtrl . "_") . $this->getFK_MapData()) . "_") . $this->getAttrOfOper()));
				break;
			case MapExtXmlList::$AutoFull:
				$this->setMyPK(((((MapExtXmlList::$AutoFull . "_") . $this->getFK_MapData()) . "_") . $this->getAttrOfOper()));
				break;
			case MapExtXmlList::$AutoFullDLL:
				$this->setMyPK(((((MapExtXmlList::$AutoFullDLL . "_") . $this->getFK_MapData()) . "_") . $this->getAttrOfOper()));
				break;
			case MapExtXmlList::$InputCheck:
				$this->setMyPK(((((MapExtXmlList::$InputCheck . "_") . $this->getFK_MapData()) . "_") . $this->getAttrOfOper()));
				break;
			case MapExtXmlList::$PageLoadFull:
				$this->setMyPK(((MapExtXmlList::$PageLoadFull . "_") . $this->getFK_MapData()));
				break;
			case MapExtXmlList::$RegularExpression:
				$this->setMyPK(((((((MapExtXmlList::$RegularExpression . "_") . $this->getFK_MapData()) . "_") . $this->getAttrOfOper()) . "_") . $this->getTag()));
				break;
			case MapExtXmlList::$BindFunction:
				$this->setMyPK(((((((MapExtXmlList::$BindFunction . "_") . $this->getFK_MapData()) . "_") . $this->getAttrOfOper()) . "_") . $this->getTag()));
				break;
			case MapExtXmlList::$Link:
				$this->setMyPK(((((MapExtXmlList::$Link . "_") . $this->getFK_MapData()) . "_") . $this->getAttrOfOper()));
				break;
			default:
				if (($DataType->IsNullOrEmpty($this->getAttrOfOper()) ==  TRUE ))
				{
					$this->setMyPK((($this->getExtType() . "_") . $this->getFK_MapData()));
				}
				else
				{
					$this->setMyPK((((($this->getExtType() . "_") . $this->getFK_MapData()) . "_") . $this->getAttrOfOper()));
				}
				break;
		}
	}
	protected function beforeInsert () 
	{
		if ($this->getMyPK()->equals(""))
		{
			$this->setMyPK(DBAccess->GenerGUID());
		}
		return parent->beforeInsert();
	}
	protected function beforeUpdate () 
	{
		$this->InitPK();
		switch ($this->getExtType()) {
			case MapExtXmlList::$ActiveDDL:
			case MapExtXmlList::$DDLFullCtrl:
			case MapExtXmlList::$TBFullCtrl:
				if (($this->getDoc()->contains("@Key") ==  FALSE ))
				{
					throw new \RuntimeException("@SQL表达式错误，您必须包含@Key ,这个关键�?. ");
				}
				break;
			case MapExtXmlList::$AutoFullDLL:
				if (($this->getDoc()->length() <= 13))
				{
					throw new \RuntimeException("@必须填写SQL表达�?. ");
				}
				break;
			case MapExtXmlList::$AutoFull:
				if (($this->getDoc()->length() <= 3))
				{
					throw new \RuntimeException("@必须填写表达�?. 比如 @单价;*@数量; ");
				}
				break;
			case MapExtXmlList::$PopVal:
				break;
			default:
				break;
		}
		return parent->beforeUpdate();
	}
	protected function afterInsertUpdateAction () 
	{
		if (($this->getExtType()->equals("MultipleChoiceSmall") ==  TRUE ))
		{
			$mypk = ((($this->getFK_MapData() . "_") . $this->getAttrOfOper()) . "T");
			$attrH = MapAttr::constructor__();
			$attrH->setMyPK($mypk);
			if (($attrH->RetrieveFromDBSources() == 0))
			{
				$attr = MapAttr::constructor__String((($this->getFK_MapData() . "_") . $this->getAttrOfOper()));
				$attrH->Copy($attr);
				$attrH->setKeyOfEn(($attr->getKeyOfEn() . "T"));
				$attrH->setName($attr->getName());
				$attrH->setUIContralType($BP->En->UIContralType->TB);
				$attrH->setMinLen(0);
				$attrH->setMaxLen(500);
				$attrH->setMyDataType(DataType->AppString);
				$attrH->setUIVisible( FALSE );
				$attrH->setUIIsEnable( TRUE );
				$attrH->setMyPK((($attrH->getFK_MapData() . "_") . $attrH->getKeyOfEn()));
				$attrH->Save();
				$attr->SetPara("MultipleChoiceSmall", "1");
			}
		}
		parent->afterInsertUpdateAction();
	}
	public static function DeleteDB () 
	{
		$exts = MapExts::constructor__();
		$exts->RetrieveAll();
		return ;
	}
}
?>
